{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import steward as st\n",
    "import matplotlib.pyplot as plt\n",
    "import pickle\n",
    "import xgboost\n",
    "from sklearn.metrics import roc_auc_score\n",
    "%matplotlib inline\n",
    "from src import build\n",
    "from src import train\n",
    "import math"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "build.build_all()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "train = st.get_instance('origin/train_30W').load()\n",
    "ids = st.get_instance('aux/train_ids').load()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "origin = train[0:100000].copy()\n",
    "origin_ids = ids[0:100000].copy()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "def roomcount_date(origin):\n",
    "    # 房间每天被看的数目\n",
    "    roomcount_date = origin.groupby(['roomid', 'orderdate']).apply(lambda x:len(x))\n",
    "    roomcount_date = pd.DataFrame(roomcount_date, columns=['roomcount_date'])\n",
    "    basicroomcount_date = origin.groupby(['basicroomid', 'orderdate']).apply(lambda x:len(x))\n",
    "    basicroomcount_date = pd.DataFrame(basicroomcount_date, columns=['basicroomcount_date'])\n",
    "\n",
    "    feature = origin[['basicroomid', 'roomid', 'orderdate']]\n",
    "    feature = pd.merge(feature, roomcount_date, left_on=['roomid', 'orderdate'], right_index=True, how='left')\n",
    "    feature = pd.merge(feature, basicroomcount_date, left_on=['basicroomid', 'orderdate'], right_index=True, how='left')\n",
    "    feature.drop(['basicroomid', 'roomid', 'orderdate'], axis=1, inplace=True)\n",
    "    return feature"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "feature"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [conda root]",
   "language": "python",
   "name": "conda-root-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
